package com.demo.project.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.demo.project.system.service.impl.OssService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.demo.project.system.domain.SysFile;
import com.demo.project.system.service.ISysFileService;
import com.demo.framework.web.controller.BaseController;
import com.demo.framework.web.page.TableDataInfo;
/**
 * 文件异步处理Controller
 * 
 * @author lichanglong
 * @date 2025-04-02
 */
@RestController
@RequestMapping("/system/file")
public class SysFileController extends BaseController
{
    @Autowired
    private ISysFileService sysFileService;

    @Autowired
    private OssService ossService;

    /**
     * 查询文件异步处理列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysFile sysFile)
    {
        startPage();
        String operName = getUsername();
        sysFile.setCreateBy(operName);
        List<SysFile> list = sysFileService.selectSysFileList(sysFile);
        return getDataTable(list);
    }

    /**
     * 下载文件
     */
    @PreAuthorize("@ss.hasPermi('system:file:download')")
    @PostMapping("/download")
    public void download(SysFile file, HttpServletResponse response)
    {
        SysFile sysFile = sysFileService.selectSysFileById(file.getId());
        String objectName = sysFile.getFilePath();
        ossService.downloadFile(objectName, response);
    }

    /**
     * 导出文件异步处理列表
     */
    /*@PreAuthorize("@ss.hasPermi('system:file:export')")
    @Log(title = "文件异步处理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysFile sysFile)
    {
        List<SysFile> list = sysFileService.selectSysFileList(sysFile);
        ExcelUtil<SysFile> util = new ExcelUtil<SysFile>(SysFile.class);
        util.exportExcel(response, list, "文件异步处理数据");
    }*/

    /**
     * 获取文件异步处理详细信息
     */
    /*@PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysFileService.selectSysFileById(id));
    }*/

    /**
     * 新增文件异步处理
     */
    /*@PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "文件异步处理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysFile sysFile)
    {
        String operName = getUsername();
        String msg = sysFileService.insertSysFile(sysFile);
        if (msg.length() > 0){
            return error(msg);
        }
        return success("新增成功");
    }*/

    /**
    * 导入文件异步处理
    */
    /*@PreAuthorize("@ss.hasPermi('system:file:import')")
    @Log(title = "文件异步处理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<SysFile> util = new ExcelUtil<SysFile>(SysFile.class);
        List<SysFile> sysFileList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String msg = sysFileService.insertSysFiles(sysFileList, operName);
        if (msg.length() > 0){
            return error(msg);
        }
        return success("导入成功");
    }*/

    /**
     * 修改文件异步处理
     */
    /*@PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "文件异步处理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysFile sysFile)
    {
        String operName = getUsername();
        String msg = sysFileService.updateSysFile(sysFile);
        if (msg.length() > 0){
            return error(msg);
        }
        return success("修改成功");
    }*/

    /**
     * 删除文件异步处理
     */
    /*@PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "文件异步处理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        String msg = sysFileService.deleteSysFileByIds(ids);
        if (msg.length() > 0){
            return error(msg);
        }
        return success("删除成功");
    }*/

    /**
    * 文件异步处理模板下载
    */
    /*@PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<SysFile> util = new ExcelUtil<>(SysFile.class);
        util.importTemplateExcel(response, "文件异步处理数据");
    }*/
}
